package com.tepth.maintenancesystem.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by LHQ on 2016/12/19.
 */

public class MaintainRefer {

    private String selectType;
    private List<Selection> selections;

    public MaintainRefer(){

    }

    public MaintainRefer(JSONObject object)throws Exception{
        this.selectType=object.getString("SelectType");
        JSONArray array=object.getJSONArray("Selections");
        this.selections=new ArrayList<>();
        for(int i=0;i<array.length();i++){
            selections.add(new Selection(array.getJSONObject(i)));
        }
    }

    public JSONObject toJSON() throws Exception {
        JSONObject json = new JSONObject();
        try {
            json.put("SelectType", selectType);
            json.put("Selections", selections);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return json;
    }

    public String getSelectType() {
        return selectType;
    }

    public void setSelectType(String selectType) {
        this.selectType = selectType;
    }

    public List<Selection> getSelections() {
        return selections;
    }

    public void setSelections(List<Selection> selections) {
        this.selections = selections;
    }

    public class Selection{
        private String code;
        private String name;
        private int sort;

        public Selection(){

        }

        public Selection(JSONObject object)throws Exception{
            this.code=object.getString("Code");
            this.name=object.getString("Name");
            this.sort=object.getInt("Sort");
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getSort() {
            return sort;
        }

        public void setSort(int sort) {
            this.sort = sort;
        }
    }
}
